package dao

import (
	"card/pkg/database"
	"gorm.io/gorm"
)

const cardDb = "card"

type common struct {
	tx *gorm.DB
}

func (c common) SetTx(tx *gorm.DB) {
	c.tx = tx
}
func (c common) GetDb() *gorm.DB {
	if c.tx != nil {
		return c.tx
	}
	return database.GetDao("card")
}

type Card struct {
	common
}

func (c Card) GetDb() *gorm.DB {
	if c.tx != nil {
		return c.tx
	}
	return database.GetDao("card")
}

type DbOption func(m *gorm.DB)

func WithWhere(query interface{}, args ...interface{}) DbOption {
	return func(m *gorm.DB) {
		m.Where(query, args)
	}
}
func WithSelect(fields []string) DbOption {
	return func(m *gorm.DB) {
		m.Select(fields)
	}
}
func WithOrder(order string) DbOption {
	return func(m *gorm.DB) {
		m.Order(order)
	}
}
